package ghostcat.manager {
	import flash.display.*;
	import flash.events.*;
	import flash.net.*;
	import flash.ui.*;

	import ghostcat.util.*;

	final public class RootManager extends Object {
		private static var _root:Sprite;
		public static const MODE_NORMAL:int = 0;
		private static var _parameters:Object = new Object();
		public static const MODE_NOSCALE:int = 1;
		private static var _initialized:Boolean = false;

		public function RootManager() {
			return;
		} // end function

		public static function get root():Sprite {
			if (!_root) {
				throw new Error("����ʹ��RootManager.register()����ע����̨");
			}
			return _root;
		} // end function

		public static function setMode(param1:int):void {
			switch (param1) {
				case MODE_NORMAL:  {
					stage.scaleMode = StageScaleMode.EXACT_FIT;
					stage.align = StageAlign.TOP;
					break;
				}
				case MODE_NOSCALE:  {
					stage.scaleMode = StageScaleMode.NO_SCALE;
					stage.align = StageAlign.TOP_LEFT;
					break;
				}
				default:  {
					break;
				}
			}
			return;
		} // end function

		public static function set root(param1:Sprite):void {
			_root = param1;
			return;
		} // end function

		public static function setValue(param1:String, param2):void {
			_parameters[param1] = param2;
			return;
		} // end function

		public static function setMenuMode(param1:int):void {
			var _loc_2:ContextMenu = new ContextMenu();
			switch (param1) {
				case MODE_NORMAL:  {
					break;
				}
				case MODE_NOSCALE:  {
					_loc_2.hideBuiltInItems();
					break;
				}
				default:  {
					break;
				}
			}
			root.contextMenu = _loc_2;
			return;
		} // end function

		public static function get initialized():Boolean {
			return _root != null;
		} // end function

		public static function register(param1:Sprite, param2:int = 1, param3:int = 1):void {
			_root = param1;
			setMode(param2);
			setMenuMode(param3);
			Tick.frameRate = stage.frameRate;
			return;
		} // end function

		public static function addURLMenu(param1:String, param2:String = null):void {
			var menuItemSelectHandler:Function;
			var label:* = param1;
			var url:* = param2;
			menuItemSelectHandler = function(event:ContextMenuEvent):void {
				navigateToURL(new URLRequest(url), "_blank");
				return;
			} // end function
			;
			var item:* = new ContextMenuItem(label);
			if (url) {
				item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemSelectHandler);
			}
			var menu:* = root.contextMenu;
			menu.customItems.push(item);
			root.contextMenu = menu;
			return;
		} // end function

		public static function getValue(param1:String) {
			if (root.loaderInfo.parameters.hasOwnProperty(param1)) {
				return root.loaderInfo.parameters[param1];
			}
			return _parameters[param1];
		} // end function

		public static function get stage():Stage {
			return root.stage;
		} // end function

	}
}
